let inspStation={};
let provinceList = [
    {id:'001',name:'上海市'}
];
let cityList = [
    {id:'001',pId:'001',name:'上海市'}
];
let countyList= [
    {id:'001',pId:'001',name:'黄埔区'},
    {id:'002',pId:'001',name:'徐汇区'},
    {id:'003',pId:'001',name:'长宁区'},
    {id:'004',pId:'001',name:'静安区'},
    {id:'005',pId:'001',name:'普陀区'},
    {id:'006',pId:'001',name:'虹口区'},
    {id:'007',pId:'001',name:'杨浦区'},
    {id:'008',pId:'001',name:'闵行区'},
    {id:'009',pId:'001',name:'宝山区'},
    {id:'010',pId:'001',name:'嘉定区'},
    {id:'011',pId:'001',name:'浦东新区'},
    {id:'012',pId:'001',name:'金山区'},
    {id:'013',pId:'001',name:'松江区'},
    {id:'014',pId:'001',name:'青浦区'},
    {id:'015',pId:'001',name:'奉贤区'},
    {id:'016',pId:'001',name:'崇明区'}
];
let initCity=function(id){
    var arr = new Array();
    $.each(cityList, function(i,row){
        if(row.pId === id) arr.push(row);
    });
    //从城市数据中过滤省份是选择的省，并刷新城市的选择器数据
    if(arr.length) $('#selectPageCity').selectPageData(arr);
};
let initCounty=function(id){
    let arr = new Array();
    $.each(countyList, function(i,row){
        if(row.pId === id) arr.push(row);
    });
    //从城市数据中过滤省份是选择的省，并刷新城市的选择器数据
    if(arr.length) $('#selectPageCounty').selectPageData(arr);
};
$(function() {
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer
            , form = layui.form;

    });

    //省份选择器初始化
    $('#selectPageProvince').selectPage({
        showField: 'name',
        keyField: 'name',
        data: provinceList,
        eSelect: function (data) {
            if(data){
                initCity(data.id);
            }
        },
        eClear: function(){//清空时，同时清空城市内容
            $('#selectPageCity').selectPageClear();
            $('#selectPageCity').selectPageData([]);
            $('#selectPageCounty').selectPageClear();
            $('#selectPageCounty').selectPageData([]);
        }
    });
//城市选择器的初始化，使用空数据进行初始化
    $('#selectPageCity').selectPage({
        showField: 'name',
        keyField: 'name',
        data: [],
        eSelect: function (data) {
            if(data){
                initCounty(data.id);
            }
        },
        eClear: function(){//清空时，同时清空城市内容
            $('#selectPageCounty').selectPageClear();
            $('#selectPageCounty').selectPageData([]);
        }
    });
    $('#selectPageCounty').selectPage({
        showField: 'name',
        keyField: 'name',
        data: []
    });

});
let initData=function (rowData) {
    let getParentId=function (name,datas) {
        let id=null;
        datas.forEach(function (row) {
            if(row.name===name){
                id=row.id;
            }
        });
        return id;
    };
    this.inspStation=rowData;
    eyc.ui.setValueUiElement($('#inspStationForm'),this.inspStation);
    initCity(getParentId(rowData.province,provinceList));
    initCounty(getParentId(rowData.prepecture,cityList));
    $('#selectPageProvince').selectPageRefresh();
    $('#selectPageCity').selectPageRefresh(rowData.prepecture);
    $('#selectPageCounty').selectPageRefresh(rowData.county);
};

// 关闭
let closeWin=function () {
    let index = parent.layer.getFrameIndex(window.name); // 获取当前窗体索引
    parent.layer.close(index); // 执行关闭
};
window.initData=initData;